package com.wmh.baseservice.user.controller;

import com.wmh.baseservice.common.utils.page.pojo.PageInfo;
import com.wmh.baseservice.common.utils.page.pojo.PageResult;
import com.wmh.baseservice.common.utils.page.pojo.SortWay;
import com.wmh.baseservice.common.utils.page.util.PageUtil;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.user.pojo.UsIncomeExpend;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.wmh.baseservice.user.service.UsIncomeExpendService;

/**
 * @author wmh generator
 * @since 2022-04-12
 */
@Api(tags = "用户端-收入流水相关接口")
@RestController
@RequestMapping(value = "user/usIncomeExpend", produces = "text/plain;charset=utf-8")
@RequiresRoles("user")
public class UsIncomeExpendController {

    @Resource
    private UsIncomeExpendService usIncomeExpendService;
    @Resource
    private HttpServletRequest request;

    @ApiOperation("列表")
    @PostMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = Long.class, name = "id", value = "id", required = false),
    })
    public String list(PageInfo pageInfo) {
        Long usId = (Long) request.getAttribute("usId");
        pageInfo.setTimeScreen("create_time");
        pageInfo.setDefaultSort("create_time", SortWay.DESC);
        //执行分页辅助工具
        PageResult<UsIncomeExpend> pageResult = new PageUtil<UsIncomeExpend>(pageInfo).startPage((page, queryWrapper) -> {
            queryWrapper.eq(UsIncomeExpend.US_ID, usId);
            usIncomeExpendService.page(page, queryWrapper);
        });
        return ReturnBody.success(pageResult);
    }

}
